<?php
// Static class, used for function groupings

class Template {
	static $template_dir;
	static $output = "";
	
	function load($file, $data=array()) {
		$file = Template::$template_dir . $file . '.php';
		if(file_exists($file)) {
			extract($data);
			ob_start();
			require $file;
			Template::$output .= ob_get_contents();
			ob_end_clean();
		}else{
			URL::show_404("Template fail: " . $file);
		}
	}

	function clear() {
		Template::$output = "";
		ob_end_clean();
	}

	function capture_start() {
		ob_start();
	}

	function capture_end() {
		Template::$output .= ob_get_contents();
		ob_end_clean();
	}

	function output() {
		echo Template::$output;
	}
}

// Setup the template engine
Template::$template_dir = Storage::get("docroot") . "/templates/default/";